package com.atldy.commerce.conf;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @version 1.0
 * @Author: lidongyang
 * @CreateTime: 2021-08-12 22:44
 * @Description：
 */
@Slf4j
@Component
public class MybatisFillConfHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Date date = new Date();
        log.info("自动插入的时间是：[{}]", DateUtil.formatDateTime(date));
        // 自动插入时间
        this.strictInsertFill(metaObject, "createTime", () ->date , Date.class);
    }


    @Override
    public void updateFill(MetaObject metaObject) {
        Date date = new Date();
        log.info("自动更新的时间是：[{}]", DateUtil.formatDate(date));
        /**自动更新时间*/
        this.strictUpdateFill(metaObject, "updateTime", () -> date, Date.class);
    }
}